#include "Display.h"
#include <SDL_opengles.h>

Display* Display::getSingleton()
{
	static Display* ms_display = 0;
	
	if(!ms_display)
	{
		ms_display = new Display();
	}
	
	return ms_display;
}

Display::Display()
{
	//
}

Display::~Display()
{
	//
}
	
bool Display::initialize()
{	
    if(SDL_Init(SDL_INIT_VIDEO) < 0)
       return false;

    /* create window and renderer */
    m_window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS);
    if(m_window == 0)
		return false;
	
    if(SDL_CreateRenderer(m_window, -1, 0) != 0)
        return false;
		
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrthof( -SCREEN_WIDTH / 2, SCREEN_WIDTH / 2, -SCREEN_HEIGHT / 2, SCREEN_HEIGHT / 2, -1, 1 );
	return true;
}

void Display::clear()
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(160.0f, 240.0f, 0.0f );
	glRotatef(270.0, 0.0, 0.0, 1.0);
	glScalef(1.0, -1.0, 1.0);
	

	SDL_RenderFill(0, 0, 0, 0, NULL);
}

void Display::flip()
{
	SDL_RenderPresent();
}

